use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use yata::core::PeriodType;
use yata::core::ValueType;

use super::IndicatorActionWrap;

///
/// Struct to hold the results of The Aroon indicator calculations.
/// Struct yata::indicators::Aroon
///
///  参见[AROON](https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/aroon-indicator)
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct AROON {
    /// When AroonUp crosses AroonDown upwards, gives full positive #0 signal.
    /// When AroonDown crosses AroonUp upwards, gives full negative #0 signal.
    /// Otherwise gives no #0 signal.
    pub signal0: Option<IndicatorActionWrap>,
    /// When AroonUp rises up to 1.0, gives full positive #1 signal.
    /// When AroonDown rises up to 1.0, gives full negative #1 signal.
    pub signal1: Option<IndicatorActionWrap>,
    /// Gives positive #2 signal when AroonUp stays above (1.0-signal_zone) and AroonDown stays under signal_zone.
    /// Gives negative #2 signal when AroonDown stays above (1.0-signal_zone) and AroonUp stays under signal_zone.
    pub signal2: Option<IndicatorActionWrap>,

    ///2 values
    ///AroonUp
    ///Range in [0.0; 1.0]
    pub up: ValueType,
    ///
    ///AroonDown
    ///Range in [0.0; 1.0]
    pub down: ValueType,
}

/// Configuration for The Aroon indicator, developed by Tushar Chande, indicates if a price is trending or is in a trading range.
/// Struct yata::indicators::Aroon
///
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct AROONConfig {
    /// main period length. Default is 14.
    ///
    /// Range in [2; PeriodType::MAX)
    pub period: PeriodType,

    /// zone value determines when signal #2 appears. Default is 0.3.
    ///
    /// Range in [0.0; 1.0]
    pub signal_zone: ValueType,

    /// period until signal #2 appears in full strength. Default is 7.
    ///
    /// Range in [1; PeriodType::MAX)
    pub over_zone_period: PeriodType,
}

impl Default for AROONConfig {
    fn default() -> Self {
        Self {
            period: 14,
            signal_zone: 0.3,
            over_zone_period: 7,
        }
    }
}
